package com.tyz.hellocst.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.tyz.hellocst.R;
import com.tyz.hellocst.entity.Goods;

import java.util.ArrayList;

public class GoodsItemAdapter extends ArrayAdapter<Goods> {

    public GoodsItemAdapter(Context context, ArrayList values) {
        super(context, R.layout.goods_item, values);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(getContext());
        View view = inflater.inflate(R.layout.goods_item, parent, false);

        Goods goods = getItem(position);

        ImageView goods_image = view.findViewById(R.id.goods_item_image);

        Bitmap bitmap = goods.getGoodsImage();
        goods_image.setImageBitmap(bitmap);

        TextView goods_name = (TextView) view.findViewById(R.id.goods_item_name);
        goods_name.setText(goods.getGoodsName());

        TextView goods_text = (TextView) view.findViewById(R.id.goods_item_text);
        goods_text.setText(goods.getGoodsText());

        TextView goods_time = (TextView) view.findViewById(R.id.goods_item_time);
        goods_time.setText(goods.getGoodsTime());

        TextView goods_owner = (TextView) view.findViewById(R.id.goods_item_owner);
        goods_owner.setText(goods.getGoodsOwner());

        return view;
    }
}
